package com.justgame.project.cloud.common.util;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间日期格式化工具
 */
public class TimeUtil {
    public static String simpleDateNow() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    }

    public static String simpleDate(Object dateObj) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateObj);
    }


    public static LocalDateTime afterTime(LocalDateTime localDate, int between, ChronoUnit chronoUnit) {
        return localDate.plus(between, chronoUnit);
    }

    /**
     * 获取从此时到明日剩余时间（毫秒）
     *
     * @return
     */
    public static long getTime2NextDay() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        return calendar.getTimeInMillis() - System.currentTimeMillis();
    }

}
